package com.android.webframework;

import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public abstract class HTTPService extends WebService {
	public abstract ResponseObject request() throws RequestException;
	
	protected InputStream requestHttp(String urlRequest) {
		HttpClient client = new DefaultHttpClient();
		try {
			HttpGet httpGet = new HttpGet(urlRequest);
			HttpResponse response = client.execute(httpGet);
			StatusLine statusLine = response.getStatusLine();
			int statusCode = statusLine.getStatusCode();
			if (statusCode == 200) {
				HttpEntity entity = response.getEntity();
				InputStream content = entity.getContent();
				return content;
			}
			else {
				throw new Exception();
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
